package com.test.user;

import java.util.List;
import java.util.Random;
import java.util.concurrent.TimeUnit;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.alibaba.fastjson.JSON;
import com.fasterxml.jackson.databind.jsonFormatVisitors.JsonAnyFormatVisitor;
import com.test.shiro.session.CustomSessionManager;
import com.test.user.bo.UserOnlineBo;

@SuppressWarnings("all")
@Controller
@RequestMapping("/")
public class UserController {
	/***
	 * 用户手动操作Session
	 * */
	@Autowired
	CustomSessionManager customSessionManager;
	@Resource
	RedisTemplate<String,Object> redisTemplate;
	@RequestMapping("getAllUser")
	@ResponseBody
	public String getAllUser(HttpServletRequest request, HttpServletResponse response) {
		List<UserOnlineBo> allUser = customSessionManager.getAllUser();
		return JSON.toJSONString(allUser);
	}
	
	
	@RequestMapping("index")
	// @ResponseBody
	public String login(HttpServletRequest request, HttpServletResponse response) {
		System.out.println(112);
		Subject subject = SecurityUtils.getSubject();
		UsernamePasswordToken token = new UsernamePasswordToken("123","123");
		token.setRememberMe(true);
		subject.login(token);
		return "loginSuccess";
	}

	/**
	 * 404错误
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("404")
	public ModelAndView _404(HttpServletRequest request) {
		ModelAndView view = new ModelAndView("404");
		return view;
	}

	/**
	 * 500错误
	 * 
	 * @param request
	 * @return
	 */
	@RequestMapping("500")
	public ModelAndView _500(HttpServletRequest request) {
		ModelAndView view = new ModelAndView("500");
		return view;
	}
}
